package com.wgh.api.client.pay;

import com.wgh.api.client.fallback.PayServiceClientFallback;
import com.wgh.common.vo.PageResult;
import com.wgh.common.vo.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.Map;

/**
 * 支付服务完整客户端接口
 * 对应PayController和ReconciliationController中的所有API
 */
@FeignClient(name = "shop-pay", fallback = PayServiceClientFallback.class)
public interface PayServiceClient {

    /**
     * 创建支付订单
     */
    @PostMapping("/api/pay/create")
    Result<?> createPayOrder(@RequestBody Map<String, Object> params);

    /**
     * 查询支付订单状态
     */
    @GetMapping("/api/pay/query/{orderId}")
    Result<?> queryPayOrderStatus(@PathVariable Long orderId);

    /**
     * 支付结果通知（异步回调）
     */
    @PostMapping("/api/pay/notify/{payType}")
    String payNotify(@PathVariable Integer payType, 
                     @RequestBody(required = false) Map<String, String> notifyData, 
                     @RequestParam(required = false) Map<String, String> queryParams);

    /**
     * 关闭支付订单
     */
    @PostMapping("/api/pay/close/{orderId}")
    Result<?> closePayOrder(@PathVariable Long orderId);

    /**
     * 发起退款
     */
    @PostMapping("/api/pay/refund")
    Result<?> refund(@RequestBody Map<String, Object> params);

    /**
     * 查询退款状态
     */
    @GetMapping("/api/pay/refund/query/{orderId}")
    Result<?> queryRefundStatus(@PathVariable Long orderId);

    /**
     * 获取支付渠道配置
     */
    @GetMapping("/api/pay/config/{payType}")
    Result<?> getPayChannelConfig(@PathVariable Integer payType);

    /**
     * 统一支付接口
     */
    @PostMapping("/api/pay/unified")
    Result<?> unifiedPay(@RequestBody Map<String, Object> payParams);

    // 以下是对账管理相关API

    /**
     * 执行对账操作
     */
    @PostMapping("/api/reconciliation/execute")
    Result<?> executeReconciliation(
            @RequestParam("reconciliationDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date reconciliationDate,
            @RequestParam(value = "payType", required = false) Integer payType);

    /**
     * 查询对账记录列表
     */
    @GetMapping("/api/reconciliation/list")
    Result<?> queryReconciliationRecords(
            @RequestParam Map<String, Object> params,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize);

    /**
     * 查询对账详情
     */
    @GetMapping("/api/reconciliation/detail/{id}")
    Result<?> getReconciliationDetail(@PathVariable Long id);

    /**
     * 生成对账报表
     */
    @GetMapping("/api/reconciliation/report")
    Result<?> generateReconciliationReport(
            @RequestParam("startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
            @RequestParam(value = "payType", required = false) Integer payType);

    /**
     * 处理对账差异
     */
    @PostMapping("/api/reconciliation/handle-diff")
    Result<?> handleReconciliationDiff(
            @RequestParam Long orderId,
            @RequestParam Integer status,
            @RequestParam(required = false) String remark);

    /**
     * 导出对账数据
     */
    @GetMapping("/api/reconciliation/export")
    Result<?> exportReconciliationData(
            @RequestParam("reconciliationDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date reconciliationDate,
            @RequestParam(value = "payType", required = false) Integer payType);

    /**
     * 上传渠道对账文件
     */
    @PostMapping("/api/reconciliation/upload-channel-file")
    Result<?> uploadChannelReconciliationFile(
            @RequestParam("file") MultipartFile file,
            @RequestParam Integer payType,
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date reconciliationDate);

    /**
     * 查询对账差异列表
     */
    @GetMapping("/api/reconciliation/diffs/{reconciliationId}")
    Result<?> getReconciliationDiffs(@PathVariable Long reconciliationId);
}